﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace AmieLib
{
   public class ServiceRunner
    {
       static bool _running = true;
       static bool _reminderInProgress = false;

       public static void Start()
       {
           //start parser on new thread, does not need to be waiting here.
           new Thread(new ThreadStart(RunReminders)).Start();
       }

       static void RunReminders()
       {
           while (_running)
           {
               if (!_reminderInProgress)
               {
                   _reminderInProgress = true;
                   AmieLib.EmailReminder.SendReminders();
                   _reminderInProgress = false;
               }
               Thread.Sleep(TimeSpan.FromSeconds(60));
           }
       }

       public static void Stop()
       {
           _running = false;
       }
    }
}
